package com.project.poetry.common.page;

import com.project.poetry.common.util.CommonUtil;
import com.project.poetry.service.entity.po.user.UserPO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 跳转页面
 * @author mengxj
 */
@Controller
@RequestMapping("page")
public class PageController {

    @GetMapping("index")
    public ModelAndView index(){
        return CommonUtil.success("login/index.html", null);
    }

    @GetMapping("reg")
    public ModelAndView reg(){
        return CommonUtil.success("login/reg.html", null);
    }

    @GetMapping("{path}/{page}")
    public ModelAndView service(@PathVariable("path") String path, @PathVariable("page") String page,
                                @RequestParam(value = "params", required = false) String params){
        return CommonUtil.success(String.format("%s/%s.html", path, page), params);
    }

    @GetMapping("{path1}/{path2}/{page}")
    public ModelAndView service1(@PathVariable("path1") String path1, @PathVariable("path2") String path2,
                                 @PathVariable("page") String page,
                                @RequestParam(value = "params", required = false) String params){
        return CommonUtil.success(String.format("%s/%s/%s.html", path1, path2, page), params);
    }

    @ResponseBody
    @GetMapping("currentUser")
    public UserPO currentUser(){
        return CommonUtil.getUser();
    }
}
